package com.zhengke.pojo.archie;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 黄保富
 * @date 2020年1月14日  
 * @version 1.0.0 
 * 创建的用于订单分页的实体类
 */
public class OrderPagination {
	
	 
	
	private static final long serialVersionUID = 1L;

	public static final String SESSION_USER_KEY = "userinfo";

	public static final String USER_POPEDOM_KEY = "userpopedom";
	
	public int start;

	public String pageNum;//页码数

	public String numPerPage;//每页的数量
	
	public String orderField;//订单的id
	
	public String orderDirection;//订单的描述
	
	/**
	 * 第一次打开的时候显示的分页的时候尽心设置的方法
	 * @param request
	 * @param response
	 */
	public void doPaginationStart(HttpServletRequest  request ,HttpServletResponse response ) {
		
		pageNum = request.getParameter("pageNum");//获取页码数
		
		numPerPage = request.getParameter("");//获取每页显示的条数
		
		// 第一次打开列表设置为一
		if (pageNum == null || "".equals(pageNum)) {
			pageNum = "1";
		}

		// 默认每页显示20条记录

		if (numPerPage == null || "".equals(numPerPage)) {
			numPerPage = "20";
		}
		
		start = (Integer.parseInt(pageNum)-1) * Integer.parseInt(numPerPage);
	}
	
	//第二打开当前的页面的时候使用的分页参数的设置的方法
	public void doPaginationEnd(int totalCount,HttpServletRequest  request ,HttpServletResponse response ) {
		
		HttpSession  session =	request.getSession();
		
		int pageNumShown = (totalCount - 1) % Integer.parseInt(numPerPage) + 1;
		
		int totalPages = 0;
			if(totalCount  % Integer.parseInt(numPerPage)>0)
				totalPages = totalCount/Integer.parseInt(numPerPage)+1;
			else
				totalPages = totalCount/Integer.parseInt(numPerPage);
		//将值放到域中去
			session.setAttribute("pageNum", pageNum);	
			session.setAttribute("numPerPage", numPerPage);
	}
	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}
	
	public String getOrderField() {
		return orderField;
	}

	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}

	public String getOrderDirection() {
		return orderDirection;
	}

	public void setOrderDirection(String orderDirection) {
		this.orderDirection = orderDirection;
	}
	
	public CurrentUser getCurrentUser(HttpServletRequest request,HttpServletResponse response) {
		return (CurrentUser)request.getSession().getAttribute(SESSION_USER_KEY);
	}
}
